package com.coocaa.app.lib.cleaner.scanner.scannerapk;

import android.content.Context;
import android.util.Log;

import com.coocaa.app.lib.cleaner.mgr.DataHolder;
import com.coocaa.app.lib.cleaner.scanner.AbstractScanner;

import java.util.List;

/**
 * Created by Eric on 2017/4/12.
 */

public class ApkScanner implements AbstractScanner {
    private Context mContext = null;
    private DataHolder mDataHolder = null;
    private ScanApkUtils sd = null;

    @Override
    public void setDataHolder(Context context, DataHolder holder) {
        mContext = context;
        mDataHolder = holder;
        sd = new ScanApkUtils(mContext);
    }

    @Override
    public void stop() {
        sd.setForceStop(true);
    }

    @Override
    public void run() {
        Log.d("ascan","ApkScanner run");
        List<ScanApkUtils.ScanData> sList = sd.scanApkList();
        if (sList != null && sList.size() > 0) {
            if (mDataHolder != null) {
                for (ScanApkUtils.ScanData data : sList) {
                    Log.d("ascan", "ApkScanner path:" + data.path + " " + data.pkg + " " + data.length + " type:" + data.apkType);
                    if (data.apkType != 1)      //未安装  可更新的app不能卸载
                        mDataHolder.appendAPK(data.path);
                }
            }
        }
    }
}
